<link rel="stylesheet" href="layui/css/layui.css">

<body class="childrenBody">

<div style="padding: 15px;">
    <form class="layui-form" action="">


        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">主队名</label>
                <div class="layui-input-block" style="width: 230px">
                    <input id="TeamID" type="hidden" name="" value="">
                    <select id="TeamID_s" lay-verify="required" name="TeamID" lay-filter="myselect">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline" style="width: 380px;">
                <label class="layui-form-label" style="width: 110px">客队名</label>
                <div class="layui-input-inline" style="width: 230px">
                    <input id="TeamID2" type="hidden" name="" value="">
                    <select id="TeamID2_s" lay-verify="required" name="TeamID2" lay-filter="myselect">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-inline" >
                <label class="layui-form-label">主队分数</label>
                <div class="layui-input-inline" style="width: 230px">
                    <input id="ScoreTeamA" type="text" name="ScoreTeamA" lay-verify="required" autocomplete="off"
                           placeholder="请输入" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 100px">客队分数</label>
                <div class="layui-input-inline" style="width: 230px">
                    <input id="ScoreTeamB" type="text" name="ScoreTeamB" lay-verify="required" autocomplete="off"
                           placeholder="请输入" class="layui-input">
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="radio" name="State" value="NULL" title="未编排">
                <input type="radio" name="State" value="-1" title="未开赛">
                <input type="radio" name="State" value="0" title="正在比赛">
                <input type="radio" name="State" value="1" title="已开赛">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline"  style="width: 340px">
                <label class="layui-form-label">赛季</label>
                <div class="layui-input-block">
                    <input id="SeasonID" type="hidden" name="" value="">
                    <select id="SeasonID_s" lay-verify="required" name="SeasonID" lay-filter="myselect">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 110px">比赛时间</label>
                <div class="layui-input-inline" style="width: 230px">
                    <input id="StartTime" type="text" name="StartTime" class="layui-input"
                           placeholder="yyyy-MM-dd HH:mm:ss">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">视频链接</label>
            <div class="layui-input-inline" style="width: 615px">
                <input id="VideoSrc" type="text" name="VideoSrc" lay-verify="required" autocomplete="off"
                       placeholder="请输入" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">战报</label>
            <div id="editor" name="Content" class="layui-input-block">
                <!--<textarea name="Content" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input"-->
                <!--style="height:200px;"></textarea>-->
                <!--<div id="editor">-->
                <!--<p name="Content"></p>-->
                <!--</div>-->
            </div>
            <!--<div class="layui-input-block">-->
            <!--<textarea name="Report" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input"-->
            <!--style="height:150px;"></textarea>-->
            <!--</div>-->
        </div>



        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" type="button" lay-submit="" lay-filter="add">立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="public/wangEditor.js"></script>
<script src="https://cdn.bootcss.com/axios/0.18.0/axios.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="layui/layui.js"></script>
<script>
    var E = window.wangEditor
    var editor = new E('#editor')
    // 或者 var editor = new E( document.getElementById('editor') )
    editor.customConfig.customUploadImg = function (files, insert) {
        var formData = new FormData();
        formData.append("file", files[0]);
        $.ajax({
            url: 'http://svcsa.org/uploadimage',
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                insert('http://svcsa.org/uploads/' + JSON.parse(data).data.savename)
            },
            error: function (data) {
                console.log(data)
            }
        });
        // files 是 input 中选中的文件列表
        // insert 是获取图片 url 后，插入到编辑器的方法
        // 上传代码返回结果之后，将图片插入到编辑器中
        // insert("http://www.pptok.com/wp-content/uploads/2012/08/xunguang-9.jpg")
    }
    editor.create();
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]);
        return null; //返回参数值
    }
    function create_edi(valu) {
        editor.txt.html(valu)
    }
    layui.use(['table', 'form', 'laydate'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#StartTime',
            type: 'datetime'
        });
        form.on('submit(add)', function (data) {
            var index = parent.layer.getFrameIndex(window.name);
            axios.post('http://svcsa.org/BBMatch/' + getUrlParam('MatchID'), {
                TeamAID: data.field.TeamID,
                TeamBID: data.field.TeamID2,
                ScoreTeamA: data.field.ScoreTeamA,
                ScoreTeamB: data.field.ScoreTeamB,
                State: data.field.State,
                StartTime: data.field.StartTime,
                Report: editor.txt.html(),
                VideoSrc: data.field.VideoSrc,
                SeasonID: data.field.SeasonID,
            })
                .then(function (response) {
                    layer.msg('修改成功', {
                        icon: 1,
                        time: 1500
                    }, function () {
                        parent.layer.close(index);
                    });
                })
                .catch(function (error) {
                    console.log(error);
                });
        });
//            赛季
        axios.get('http://svcsa.org/BBSeason', {}).then(function (response) {
            console.log(response);
            $.each(response.data.data, function (index, item) {
                $('#SeasonID_s').append('<option value="' + item.SeasonID + '">' + item.SeasonName + '</option>');
            });
            form.render();
            var num = $("#SeasonID").val();
            var numbers = $("#SeasonID_s").find("option"); //获取select下拉框的所有值
            console.log(numbers);
            for (var j = 1; j < numbers.length; j++) {
                console.log(numbers);
                if ($(numbers[j]).val() == num) {
                    console.log('ok');
                    $(numbers[j]).attr("selected", "selected");
                    $(numbers[j]).attr("class", "layui-this");
                    form.render();
                }
            }
        })
//                主队
        axios.get('http://svcsa.org/BBTeam', {}).then(function (response) {
            console.log(response);
            $.each(response.data.data, function (index, item) {
                $('#TeamID_s').append('<option value="' + item.ID + '">' + item.Name + '</option>');
            });
            form.render();
            var num = $("#TeamID").val();
            var numbers = $("#TeamID_s").find("option"); //获取select下拉框的所有值
            console.log(numbers);
            for (var j = 1; j < numbers.length; j++) {
                console.log(numbers);
                if ($(numbers[j]).val() == num) {
                    console.log('ok');
                    $(numbers[j]).attr("selected", "selected");
                    $(numbers[j]).attr("class", "layui-this");
                    form.render();
                }
            }
        })
//                客队
        axios.get('http://svcsa.org/BBTeam', {}).then(function (response) {
            console.log(response);
            $.each(response.data.data, function (index, item) {
                $('#TeamID2_s').append('<option value="' + item.ID + '">' + item.Name + '</option>');
            });
            form.render();
            var num = $("#TeamID2").val();
            var numbers = $("#TeamID2_s").find("option"); //获取select下拉框的所有值
            console.log(numbers);
            for (var j = 1; j < numbers.length; j++) {
                console.log(numbers);
                if ($(numbers[j]).val() == num) {
                    console.log('ok');
                    $(numbers[j]).attr("selected", "selected");
                    $(numbers[j]).attr("class", "layui-this");
                    form.render();
                }
            }
        })

            .catch(function (error) {
                console.log(error);
            });
    });
</script>

</body>